package com.tj.collection.controller.admin.response;

import com.fqgj.common.api.ResponseData;
import com.fqgj.common.utils.CollectionUtils;
import com.qianli.cashmama.product.facade.result.ProductCategory;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created with IntelliJ IDEA.
 * User: nengfei (mr.vencnet@gmail.com)
 * Date: 2016/11/22
 * Time: 下午1:25
 */
public class ProductTypeListResponse implements ResponseData {
    private List<Item> list = new ArrayList<>();

    public ProductTypeListResponse(List<ProductCategory> productCategoryList, List<ProductCategory> categoriesOfCurrentMerchant) {

        if (CollectionUtils.isEmpty(categoriesOfCurrentMerchant) || CollectionUtils.isEmpty(productCategoryList)) {
            return;
        }
        List<String> collect = categoriesOfCurrentMerchant.parallelStream().map(ProductCategory::getCode).collect(Collectors.toList());
        for (int i = 0; i < productCategoryList.size(); i++) {
            ProductCategory productCategory = productCategoryList.get(i);
            if (!collect.contains(productCategory.getCode())) {
                continue;
            }
            Item item = new Item()
                    .setCode(productCategory.getCode())
                    .setName(productCategory.getName());
            list.add(item);
        }

    }


    private class Item {
        //类目代码
        private String code;

        //类目名称
        private String name;

        public String getCode() {
            return code;
        }

        public Item setCode(String code) {
            this.code = code;
            return this;
        }

        public String getName() {
            return name;
        }

        public Item setName(String name) {
            this.name = name;
            return this;
        }
    }
}
